home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5087 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  36 lines

  1. Newsgroups: comp.lang.c
  2. Path: uu4news.netcom.com!friend!news
  3. From: rich@kastle.com (Richard Krehbiel)
  4. Subject: Re: Can I assume the FIRST field of a STRUCT is at OFFSET 0?
  5. Message-ID: <1996Feb8.175304.3443@friend.kastle.com>
  6. Sender: news@friend.kastle.com (News)
  7. Reply-To: rich@kastle.com
  8. Organization: Kastle Development Associates
  9. X-Newsreader: Forte Free Agent 1.0.82
  10. References: <KIN.96Feb7142238@sampras.isi.com>
  11. Date: Thu, 8 Feb 1996 17:52:42 GMT
  12.  
  13. kin@isi.com (Kin Cho) wrote:
  14.  
  15. >I couldn't find reference to this in the K&C book.
  16. >Is this specified one way or the other in ANSI C?
  17. >Have you run into a platform where this assumption fails?
  18.  
  19. >Please email if possible.
  20.  
  21. The standard says that what you're doing is guaranteed.  A pointer to
  22. a struct "equals" a pointer to it's first member.  The first structure
  23. member must have offset zero, and consecutively declared structure
  24. members (not including bit fields) must be at increasing offsets, as
  25. given by the offsetof macro.  I depend on this myself.
  26.  
  27. (BTW the C++ standard agrees so long as the struct is a "Plain Old
  28. Data Structure" (PODS); i.e. it may not be a derived class and it must
  29. have no virtual functions.  In fact, the offsetof macro is only
  30. defined for a PODS, a fact I find distressing.)
  31.  
  32. --
  33. Richard Krehbiel, Kastle Systems, Arlington VA USA
  34. rich@kastle.com (work) or richk@mnsinc.com (personal)
  35.  
  36.